package com.wtwd.campus.receiver;

import com.wtwd.campus.entity.MqIccidAndSimCard;
import com.wtwd.campus.entity.MqLocationData;
import com.wtwd.campus.service.IRMFeignClientService;
import com.wtwd.campus.service.InjectFeignService;
import com.wtwd.campus.utils.LocationUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class DeviceSimAndIccidReceiver implements Receiver {
    @Autowired
    private IRMFeignClientService irmFeignClientService;
    @Override
    public String parseMessage(String data) {
        //*TJ,2020916012,V4,GETICCID,130305,111111,86954789991234566958, 13612345678,A,2212.8745,N,11346.6574,E,14.28,028,220902,FFFFFFFF#
        String[] split = data.split(",");
        String imei = split[1];
        String messageType = split[2];
        String type = split[3];
        String commandNumber = split[4];
        String deviceTime = split[5];
        String Iccid = split[6];
        String phone = split[7];
        String latitude = split[9];
        String longitude = split[11];
        String speed = split[13];
        String orientation = split[14];
        String deviceDate = split[15];
        String deviceStatus = split[16];
        MqIccidAndSimCard mqIccidAndSimCard = new MqIccidAndSimCard();
        mqIccidAndSimCard.setCommandNumber(commandNumber);
        mqIccidAndSimCard.setDeviceDate(deviceDate);
        mqIccidAndSimCard.setDeviceStatus(deviceStatus);
        mqIccidAndSimCard.setDeviceTime(deviceTime);
        mqIccidAndSimCard.setImei(imei);
        mqIccidAndSimCard.setPhone(phone);
        mqIccidAndSimCard.setIccid(Iccid);
        MqLocationData mqLocationData = new MqLocationData();
        mqLocationData.setOrientation(Integer.parseInt(orientation));
        mqLocationData.setSpeed(Double.parseDouble(speed));
        List<Double> latlng = LocationUtils.transiformLatAndLng(longitude,latitude);
        mqLocationData.setLatitude(latlng.get(1));
        mqLocationData.setLongitude(latlng.get(0));
        mqIccidAndSimCard.setMqLocationData(mqLocationData);
        InjectFeignService.getIrmFeignClientService().querySimCardAndIccidResponse(mqIccidAndSimCard);
        return imei;
    }
}
